<template>
	<view class="tabbar_top">
		<view class="param_search">
			<view @click="sortFilter = !sortFilter">
				<text>{{sortText}}</text>
				<text class="iconfont icon-caret-down"></text>
				<view class="filter-box" :class="{'active-filter-box':sortFilter}" @touchmove.stop.prevent="moveHandle">
					<view class="filter-cnt">
						<view :class="{'check-text':orderByColumn == text.orderByColumn}"
							@click.stop="onSort(text.orderByColumn,text.isAsc)" v-for="(text,idx) in sortList"
							:key="idx">
							{{text.text}}
						</view>
					</view>
				</view>
			</view>
			<view @click="serviceFilter = !serviceFilter">
				<text>服务商</text>
				<text class="iconfont icon-caret-down"></text>
				<view class="filter-box" :class="{'active-filter-box':serviceFilter}"
					@touchmove.stop.prevent="moveHandle">
					<view class="service-cnt">
						<scroll-view class="scroll-view" scroll-y="true">
							<view class="scroll-view-item " :class="{'item-check':item.check}"
								v-for="(item,index) in shopList" :key="index" @click.stop="item.check = !item.check">
								<text>{{item.storeName}}</text>
							</view>
						</scroll-view>
						<view class="btn flex">
							<view @click.stop="serviceItem(1)">重置</view>
							<view @click.stop="serviceItem(2)">确认</view>
						</view>
					</view>
				</view>
			</view>
			<view @click="whereFilter = !whereFilter">
				<text>筛选</text>
				<text class="iconfont icon-shaixuan"></text>
				<view class="filter-box" :class="{'active-filter-box':whereFilter}"
					@touchmove.stop.prevent="moveHandle">
					<view class="where-cnt">
						<slot name="whereCnt"></slot>
					</view>
				</view>
			</view>
		</view>
		<view class="t_search" :class="{'active_search':isSearch}">
			<view class="line" v-if="!isSearch"></view>
			<uni-icons type="search" color="#ccc" size="20" @click="isSearch = true"></uni-icons>
			<input class="ipt" v-if="isSearch" placeholder="搜索服务商/技师" />
			<uni-icons v-if="isSearch" type="closeempty" color="#ccc" size="20" @click="isSearch = false">
			</uni-icons>
		</view>
	</view>
</template>

<script>
	export default {
		name: "sortFilter",
		data() {
			return {
				isSearch: false,
				sortFilter: false,
				serviceFilter: false,
				whereFilter: false,
				orderByColumn: "",
				sortList: [{
					text: '综合排序',
					orderByColumn: '',
					isAsc: ''
				}, {
					text: '订单最多',
					orderByColumn: 't.total_order desc, t.id',
					isAsc: 'desc'
				}, {
					text: '距离最近',
					orderByColumn: 't.distance, t.id',
					isAsc: 'desc'
				}, {
					text: '最近加入',
					orderByColumn: 't.create_time desc, t.id',
					isAsc: 'desc'
				}, {
					text: '评分最高',
					orderByColumn: 't.score desc, t.id',
					isAsc: 'desc'
				}]
			};
		},
		props: {
			shopList: {
				type: Array,
				default: () => {
					return []
				}
			}
		},
		computed: {
			sortText() {
				let arr = this.sortList.filter(item => item.orderByColumn == this.orderByColumn)
				return arr[0].text
			}
		},
		methods: {
			serviceItem(item) {
				console.log(item)
			},
			onSort(t1, t2) {
				this.orderByColumn = t1
				this.$emit('onSort', {
					orderByColumn: t1,
					isAsc: t2
				})
				this.sortFilter = false
			},
			serviceItem(idx) {
				if (idx == 1) {
					this.$emit('serviceItem', '')
				} else {
					let arr = this.shopList.filter(val => val.check)
					arr = arr.map(item => {
						return item.id
					})
					this.$emit('serviceItem', arr.join(','))
				}
				this.serviceFilter = false
			},
			onSearch() {
				this.isSearch = !this.isSearch
			},
			moveHandle() {
				return true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar_top {
		width: 100%;
		height: 80rpx;
		background: #fff;
		box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .06);
		position: fixed;
		box-sizing: border-box;
		left: 0;
		top: calc(var(--status-bar-height) + 88rpx);
		padding-right: 124rpx;
		z-index: 99;

		.param_search {
			padding: 0 30rpx;
			font-size: 26rpx;
			font-weight: 400;
			color: #666;
			display: flex;
			align-items: center;
			height: 78rpx;
			justify-content: space-between;
			position: relative;

			>view {
				text-align: center;
				height: 78rpx;
				line-height: 80rpx;
				font-size: 26rpx;
				font-weight: 400;
				color: #666;

				.icon-caret-down {
					font-size: 28rpx;
					color: #ccc;
				}
			}

			.filter-box {
				width: 100vw;
				height: 0px;
				overflow: hidden;
				top: 78rpx;
				left: 0;
				background-color: rgba(#333, .4);
				position: absolute;
				z-index: 9;
				transition: all .5s;

				.where-cnt {
					margin-left: 20%;
					width: 80%;
					height: 100%;
					background-color: #fff;
				}

				.service-cnt {
					width: 100%;
					height: 50vh;
					background-color: #ffffff;
					box-sizing: border-box;
					padding: 10px 0 0;

					.btn {
						width: 100%;
						height: 88rpx;
						border-top: 2rpx solid #eee;

						>view {
							flex: 1;
							text-align: center;
							line-height: 88rpx;
							height: 88rpx;
							font-size: 24rpx;

							&:last-child {
								background-color: #f308fe;
								color: #fff;
							}
						}
					}

					.scroll-view {
						width: 100%;
						height: calc(50vh - 108rpx);
						flex-wrap: wrap;
						text-align: left;
						padding: 0 20rpx;
						box-sizing: border-box;

						.scroll-view-item {
							display: inline-block;
							width: calc(33.3% - 16rpx);
							height: 50rpx;
							line-height: 50rpx;
							background: #f8f8f8 url(/static/icon_store_chk.png) no-repeat 20rpx 50%;
							background-size: 36rpx auto;
							margin-right: 19rpx;
							padding-left: 34px;
							color: #666;
							font-size: 24rpx;
							box-sizing: border-box;
							border-radius: 6rpx;

							text {
								display: block;
								flex: 1;
								height: 50rpx;
								word-break: keep-all;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
								padding-right: 16rpx;
							}

							&:nth-child(3n + 3) {
								margin-right: 0rpx;
							}
						}

						.item-check {
							background: #fdebfe url(/static/icon_store_chked.png) no-repeat 20rpx 50%;
							background-size: 36rpx auto;
							color: #f308fe;
						}
					}
				}

				.filter-cnt {
					width: 100%;
					background-color: #fff;

					>view {
						text-align: left;
						width: 100%;
						height: 80rpx;
						line-height: 80rpx;
						color: #666;
						font-size: 24rpx;
						overflow: hidden;
						position: relative;
						box-sizing: border-box;
						padding: 0 30rpx;
						border-bottom: 2rpx solid #f8f8f8;
					}

					.check-text {
						color: rgb(141, 95, 240);
						;
					}
				}
			}

			.active-filter-box {
				height: calc(100vh - 260rpx) !important;
			}
		}

		.t_search {
			width: 100rpx;
			height: 80rpx;
			position: absolute;
			right: 0;
			top: 0;
			display: flex;
			align-items: center;
			transition: all .5s;

			.line {
				margin-right: 30rpx;
				width: 2rpx;
				height: 24rpx;
				background: #d8d8d8;
			}
		}

		.active_search {
			width: 100%;
			background-color: #fff;
			padding: 0 20rpx;
			box-sizing: border-box;

			.ipt {
				flex: 1;
				margin: 0 32rpx;
				font-size: 28rpx;
			}
		}
	}
</style>
